import moment from "moment";
/**
 * 转换时间
 * @param date
 * @param type
 */
export const formatDateByISO = (date: string, type?: 1) => {
  const format = type === 1 ? "YYYY-MM-DD HH:mm" : "YYYY-MM-DD HH:mm:ss";
  return moment(date).format(format);
};

/**
 * 获取数字区间的集合
 * @param start 开始
 * @param end 结束
 * @returns
 */
export const range = (start: number, end: number) => {
  const result = [];
  for (let i = start; i < end; i++) {
    result.push(i);
  }
  return result;
};

export const getRandom = (number: number = 10): number => {
  return Math.ceil(Math.random() * number);
};

// 获取随机数组
export const getRandomArr = (): number[] => {
  return Array.from({ length: Math.floor(Math.random() * 10) }, (v, i) => i);
};

export const getRndInteger = (min: number, max: number) => {
  return Math.floor(Math.random() * (max - min) + min);
};
